/**
 * Created by Eric.Dou on 4/16/14.
 */
define(function (require) {
    var comm = require('lib/commons');

    return function (helper, $) {
        helper.register('lazyLoad', function (options) {
            this.condition = function (opt) {
                if (!comm.hasPro(options, 'target')) {
                    return false;
                }
                if (!comm.hasPro(options, 'html')) {
                    return false;
                }
                var html = options['html'];
                //if have the lazyload property mean ,the content should be lazy load by server response.SO don't need do nothing.
                if (!comm.hasPro(html, 'lazyLoad')) {
                    return false;
                }
                return true;
            };
            var html = options['html'], lazyLoadSub = {};
            if (comm.hasPro(options, 'lazyLoad')) {
                var optTarget = comm.hasPro(options, 'target') ? options['target'] : null;
                $.extend(lazyLoadSub, html['lazyLoad'], {target: optTarget, callBackOptions: options}, {lazyLoad: false});
                comm.lazyLoadCompont(lazyLoadSub, function (opt) {
                    var act = helper.findOrCreateAction(opt, "addEventListenerfunction");
                    act.process(opt);
                })
            }

        });
    }
});